package com.aizhixin.lab.course.course.controller;

import com.aizhixin.lab.account.dto.AccountDTO;
import com.aizhixin.lab.account.service.AccountService;
import com.aizhixin.lab.common.core.PageData;
import com.aizhixin.lab.common.utils.TokenUtil;
import com.aizhixin.lab.course.course.entity.CourseAssist;
import com.aizhixin.lab.course.course.service.TeacherCourseAssistService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/course/student/assist")
@Api(value = "学生课程辅助资料相关API")
public class StudentCourseAssistController {
    @Autowired
    private AccountService accountService;
    @Autowired
    private TeacherCourseAssistService assistService;

    @RequestMapping(value = "/getList", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(httpMethod = "GET", value = "查询文件列表,预览时用", response = Void.class, notes = "查询文件列表,预览时用<br>@author hsh")
    public ResponseEntity<?> getList(@RequestHeader("Authorization") String token,
                                     @ApiParam(value = "courseId", required = false) @RequestParam(value = "courseId", required = false) String courseId,
                                     @ApiParam(value = "parentId", required = false) @RequestParam(value = "parentId", required = false) Long parentId,
                                     @ApiParam(value = "pageNumber 起始页") @RequestParam(value = "pageNumber", required = false) Integer pageNumber,
                                     @ApiParam(value = "pageSize 每页的限制数目") @RequestParam(value = "pageSize", required = false) Integer pageSize) {
        AccountDTO account = accountService.getUserByToken(token);
        if (account == null) {
            return new ResponseEntity<Object>(TokenUtil.tokenValid(), HttpStatus.UNAUTHORIZED);
        }
        PageData<CourseAssist> result = assistService.getListWithoutHide(courseId, parentId, pageNumber, pageSize);
        return new ResponseEntity(result, HttpStatus.OK);
    }
}
